//
//  QSHomeViewController.m
//  SinaWeiBo
//
//  Created by apple on 16/5/28.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "QSHomeViewController.h"
#import "QSVistorLonginView.h"
#import "QSUserAccountViewModel.h"
#import "QSTitleBtn.h"
#import "QSScanViewController.h"

@interface QSHomeViewController ()

@end

@implementation QSHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 设置导航栏
    [self setupNav];
    
    // 判断用户是否登录
    if ([[[QSUserAccountViewModel alloc] init] isUserLongin]) {
        // 获取用户信息
        [self setupUserInfo];
        
        // 添加下拉刷新
        [self setupRefresh];
    }else{
        
        // 创建用户登录视图
        [self.visitorView setupInfoWithImageName:@"visitordiscover_feed_image_house" andText:@"关注一些人，回这里看看有什么惊喜"];
    }
}

#pragma mark - 内部调用方法
/**
 *  设置导航栏
 */
- (void)setupNav
{
    // 标题
    QSTitleBtn *titleBtn = [[QSTitleBtn alloc] init];
    [titleBtn setTitle:@"首页" forState:UIControlStateNormal];
    // 设置默认状态图片
    [titleBtn setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
    // 设置选中状态图片
    [titleBtn setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];
    [titleBtn sizeToFit];
    
    // 监听标题按钮点击事件
    [titleBtn addTarget:self action:@selector(titleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.titleView = titleBtn;
    
    // 导航栏左右两边的按钮
    // 搜索好友
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_friendsearch" higImage:@"navigationbar_friendsearch_highlighted" target:self action:@selector(firendSearch)];
    
    // 扫描（二维码）
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_pop" higImage:@"navigationbar_pop_highlighted" target:self action:@selector(scan)];
}

/**
 *  按钮点击事件
 */
- (void)titleBtnClick:(QSTitleBtn *)titleBtn
{
    
}

/**
 *  搜索好友
 */
- (void)firendSearch
{
    QSLog(@"搜索好友");
}

/**
 *  扫描（二维码）
 */
 - (void)scan
{
    // 跳转到扫描二维码的界面
    // 创建storyBoard
    UIStoryboard  *sb = [UIStoryboard storyboardWithName:@"QSScanViewController" bundle:nil];
    
    // 创建storyBoard控制器（storyBoard中的is initial view Controller的勾要打上）
    QSScanViewController *scanVc = [sb instantiateInitialViewController];
    
    // 弹出控制器界面
    [self presentViewController:scanVc animated:YES completion:nil];
}

/**
 *  获取用户信息
 */
- (void)setupUserInfo
{
    
}
/**
 *  添加下拉刷新
 */
- (void)setupRefresh
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
